import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_juwo/common/common_index.dart';
import 'package:flutter_juwo/ui/custom/TimerWidget.dart';
import 'package:flutter_juwo/ui/utils/utils.dart';

class BottomWidgets extends StatefulWidget {
  @override
  _BottomWidgetsState createState() => _BottomWidgetsState();
}

class _BottomWidgetsState extends State<BottomWidgets> {
  TextEditingController checkController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.fromLTRB(
          0, ScreenUtil().setWidth(30), 0, ScreenUtil().setWidth(30)),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            margin: EdgeInsets.fromLTRB(
                ScreenUtil().setWidth(30), 0, ScreenUtil().setWidth(30), 0),
            child: Text(
              "产品核对",
              style: TextStyles.custom(
                  28, Colours.appC1, Font.PingFangBlod),
            ),
          ),
          Container(
            margin: EdgeInsets.fromLTRB(ScreenUtil().setWidth(30),
                ScreenUtil().setWidth(30), ScreenUtil().setWidth(30), 0),
            child: Row(
              children: <Widget>[
                Container(
                  child: Text("请输入产品链接或者淘口令，核对商品", style: getTextStyle()),
                ),
                Expanded(
                  flex: 1,
                  child: GestureDetector(
                    onTap: () {},
                    child: Container(
                      alignment: Alignment.centerRight,
                      child: Text(
                        "如何复制链接？",
                        style: TextStyles.custom(24, Color(0xFF508cff),
                            Font.PingFangMedium),
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
          Container(
            margin: EdgeInsets.fromLTRB(ScreenUtil().setWidth(30),
                ScreenUtil().setWidth(30), ScreenUtil().setWidth(30), 0),
            height: ScreenUtil().setWidth(100),
            decoration: BoxDecoration(
                border: Border.all(
                    color: Color(0xFFe5e5e5), width: ScreenUtil().setWidth(1)),
                borderRadius: BorderRadius.circular(5)),
            child: TextField(
              maxLines: 5,
              controller: checkController,
              style: TextStyle(
                  fontSize: ScreenUtil().setSp(24),
                  color: Color(0xFF666666),
                  fontFamily: Font.PingFangMedium),
              decoration: InputDecoration(
                  contentPadding: EdgeInsets.all(0), border: InputBorder.none),
            ),
          ),
          Container(
            alignment: Alignment.center,
            margin: EdgeInsets.fromLTRB(
                0, ScreenUtil().setWidth(28), 0, ScreenUtil().setWidth(34)),
            child: GestureDetector(
              onTap: () {
                getClipboardContents();
              },
              child: Container(
                width: ScreenUtil().setWidth(340),
                height: ScreenUtil().setWidth(60),
                decoration: BoxDecoration(
                    color: Color(0xFFe3393c),
                    borderRadius: BorderRadius.circular(15)),
                alignment: Alignment.center,
                child: Text(
                  "粘贴并核对",
                  style: TextStyles.custom(
                      28, Colors.white, Font.PingFangMedium),
                ),
              ),
            ),
          ),
          UiUtils.dividerWidget(ScreenUtil().setWidth(20)),
          Container(
            margin: EdgeInsets.fromLTRB(
                ScreenUtil().setWidth(30), ScreenUtil().setWidth(30), 0, 0),
            child: Text(
              "验证产品问题：",
              style: getTextStyle(),
            ),
          ),
          Container(
            margin: EdgeInsets.fromLTRB(ScreenUtil().setWidth(30),
                ScreenUtil().setWidth(30), ScreenUtil().setWidth(30), 0),
            child: Text(
              "请输入页面详情页得产品型号：（提示：6位字母）",
              style: getTextStyle(),
            ),
          ),
          Container(
            margin: EdgeInsets.fromLTRB(ScreenUtil().setWidth(30),
                ScreenUtil().setWidth(30), ScreenUtil().setWidth(30), 0),
            height: ScreenUtil().setWidth(60),
            decoration: BoxDecoration(
                border: Border.all(
                    color: Color(0xFFe5e5e5), width: ScreenUtil().setWidth(1)),
                borderRadius: BorderRadius.circular(5)),
            child: Row(
              children: <Widget>[
                Expanded(
                  flex: 1,
                  child: TextField(
                    decoration: InputDecoration(
                      border: InputBorder.none,
                      contentPadding: EdgeInsets.all(0)
                    ),
                  ),
                ),
                Container(
                  decoration: BoxDecoration(
                      color: Color(0xFFe3393c),
                      borderRadius:
                          BorderRadius.horizontal(right: Radius.circular(5))),
                  alignment: Alignment.center,
                  height: ScreenUtil().setWidth(60),
                  width: ScreenUtil().setWidth(230),
                  child: Text(
                    "核对",
                    style: TextStyles.custom(
                        24, Colors.white, Font.PingFangMedium),
                  ),
                )
              ],
            ),
          ),
          Container(
            margin: EdgeInsets.fromLTRB(
                0, ScreenUtil().setWidth(62), 0, ScreenUtil().setWidth(100)),
            alignment: Alignment.center,
            child: GestureDetector(
              onTap: (){
                Application.router.navigateTo(context, Routes.orderPayment);

              },
              child: Container(
                alignment: Alignment.center,
                height: ScreenUtil().setWidth(88),
                width: ScreenUtil().setWidth(450),
                decoration: BoxDecoration(
                    color: Color(0xFFffdedf),
                    borderRadius: BorderRadius.circular(22)),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Container(
                      alignment: Alignment.center,
                      height: ScreenUtil().setWidth(52),
                      margin: EdgeInsets.only(right: ScreenUtil().setWidth(18)),
                      padding: EdgeInsets.fromLTRB(5, 0, 5, 0),
                      decoration: BoxDecoration(
                        color: Color(0xFFdf3033),
                        borderRadius: BorderRadius.circular(3)

                      ),
                      child: TimerWidget(
                        152,
                        onRun: (v){},
                        onFinsh: (){},
                        day: ":",
                        hour: ": ",
                        min: ": ",
                        second: "",
                        end: "",
                        color: 0xFFFFFFFF,
                        fontSize: 28.0,
                      ),
                    ),
                    Text(
                      "后，下一步",
                      style: TextStyles.custom(
                          24, Color(0xFFdf3033), Font.PingFangMedium),
                    )
                  ],
                ),
              ),
            ),
          )
        ],
      ),
    );
  }

  getClipboardContents() async {
    ///1.使用异步调用获取返回值
    var clipboardData = await Clipboard.getData(Clipboard.kTextPlain);
    if (clipboardData != null) {
      ///调用Flutter的State重新赋值加载界面
      this.setState(() {
        ///将异步获取到的文本数据赋值到全局字符串对象上，我这里是将粘贴板上面的内容赋值到TextField元素的TextEditingController控制器上
        checkController.text = clipboardData.text;
      });
    }

    ///2.开始核对
  }

  getTextStyle() {
    return TextStyles.custom(
        24, Color(0xFF666666), Font.PingFangMedium);
  }
}
